import Vue from 'vue'
import VueRouter from 'vue-router'
//导入NProgress进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Vue.use(VueRouter)
//路由信息数组   不要加花括号成了函数


//首页验证页面
const Index = () => import('../views/index/Index.vue')


//首页
const Home = ()=>import('../views/index/Home')
// const IndexReally = ()=>import('../views/index/IndexReally')
const IndexProduct = ()=>import('../views/index/IndexProduct/IndexProduct.vue')
const IndexIntegralStore = ()=>import('../views/index/IndexIntegralStore/IndexIntegralStore.vue')
const PersonalCenter = ()=>import('../views/index/PersonalCenter/PersonalCenter.vue')
const PersonIndex = ()=>import('../views/index/PersonalCenter/PersonIndex/PersonIndex.vue')
const PersonAcount = ()=>import('../views/index/PersonalCenter/PersonAcount/PersonAcount.vue')
const PersonIntegral = ()=>import('../views/index/PersonalCenter/PersonIntegral/PersonIntegral.vue')
const PersonOrder = ()=>import('../views/index/PersonalCenter/PersonOrder/PersonOrder.vue')



//后台管理
const Layout = () => import('../views/administrators/Layout.vue')
const Admin = ()=>import('../views/administrators/admin/Admin.vue')
const ProductUpdate = () => import('../views/administrators/productUpdate/ProductUpdate.vue')
const IntegralUpdate = () => import('../views/administrators/integralUpdate/IntegralUpdate.vue')
const Complain = () => import('../views/administrators/complain/Complain.vue')


const routes = [
  //首页
  { path: '/',
    meta: { title:'Boss系统'},
    // component: Index
    component: Home,
    children:[
          {
            path: 'indexProduct',
            meta: { title:'Boss系统-产品' },
            component: IndexProduct
          },
          { 
            path: 'indexIntegral',
            meta: { title:'Boss系统-积分商城' },
            component: IndexIntegralStore },
          { 
            path: 'personalCenter',
            meta: { title:'Boss系统-个人中心' },
            component: PersonalCenter,
            children:[
              {
                path: 'personIndex',
                meta: { title:'Boss系统-产品' },
                component: PersonIndex,
              },
              {
                path: 'PersonAcount',
                meta: { title:'Boss系统-产品' },
                component: PersonAcount,
              },
              {
                path: 'PersonIntegral',
                meta: { title:'Boss系统-产品' },
                component: PersonIntegral,
              },
              {
                path: 'PersonOrder',
                meta: { title:'Boss系统-产品' },
                component: PersonOrder,
              },
            ]
           }
        ]
  },
   //登录验证页  是否无需登录
   {
    path:'/loginTest',
    meta: { title:'Boss系统-登录' },  
    component:() => import('../views/index/Index.vue')
  },
  //登录页
  {
    path:'/login',
    meta: { title:'Boss系统-登录' },  
    component:() => import('../views/index/Login.vue')
  },
  
  //后台管理页
  { 
    path: '/layout',
    meta: { title:'Boss系统-管理员' },
    component: Layout ,
    children:[
      { 
        path: 'admin',
        meta: { title:'账户管理' },
       component: Admin },
      { 
        path: 'productUpdate',
        meta: { title:'产品管理' },
        component: ProductUpdate },
      { 
        path: 'integralUpdate',
        meta: { title:'积分管理' },
        component: IntegralUpdate },
      { 
        path: 'complain',
        meta: { title:'积分管理' },
        component: Complain },
    ]
  }
]

const router = new VueRouter({
  mode: 'history', 
  base: process.env.BASE_URL, 
  routes 
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  // ...设置title
  if(to.meta && to.meta.title){
    document.title = to.meta.title
  }
  next()
})

router.afterEach((to, from) => {
  // ...
  NProgress.done()
})
   
export default router
